package com.kotlindemo.app.base

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.classic.common.MultipleStatusView
import com.kotlindemo.app.application.MyApplication

/**
 * Created by yang on 2018/6/27.
 */
abstract class BaseActivity : AppCompatActivity() {

    protected var mLayoutStatusView: MultipleStatusView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(layoutId())
        initView()
        start()
        initData()
        initListener()
    }

    private fun initListener(){
        mLayoutStatusView?.setOnClickListener(mRetryClickListener)
    }

    open val mRetryClickListener: View.OnClickListener = View.OnClickListener {
        start()
    }

    abstract fun layoutId(): Int
    abstract fun initData()
    abstract fun initView()
    abstract fun start()

    override fun onDestroy() {
        super.onDestroy()
        MyApplication.getRefWatcher(this)?.watch(this)
    }

}